<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */

class DB_PostgreSQL {

	public $conn;
	public $query_count;

	function __construct($host, $user, $pass, $db){

		$query_string = 'host='.$host.' user='.$user.' password='.$pass;
		if( !( $this->conn = pg_connect( (string)$query_string ) ) ) {
            die( "<h1>Cannot establish connection to DB through <strong>PostgreSQL</strong> driver!</h1>" );
		}
		pg_query("SET NAMES utf8");
		return $this->conn;
	}

	function query( $query ) {
        $this->query_count++;
        $query = str_replace('{prefix}', $GLOBALS['db_prefix'], $query);
		return pg_query( $this->conn,  $query);
	}

	function fetch_array( $result ) {
		return pg_fetch_array( $result );
	}

	function fetch_object( $result ) {
		return pg_fetch_object( $result );
	}

    function real_escape_string( $escapestr ) {
		return pg_escape_string( $escapestr );
	}
	
	function error(){
		return pg_errormessage();
	}
}

?>